package models;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import play.db.jpa.Model;

@Entity
public class Comarca extends Model {

	@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "comarca")
	private Set<Competencia> competencias = new HashSet<Competencia>();

	@ManyToOne(cascade = CascadeType.ALL, optional = false)
	private UF uf;

	@Column(nullable = false)
	private String nome;

	public Set<Competencia> getCompetencias() {
		return competencias;
	}

	public void addCompetencia(Competencia competencia) {
		if (competencia != null) {
			competencia.setComarca(this);
			this.competencias.add(competencia);
		}
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public void setUf(UF uf) {
		this.uf = uf;
	}

	public UF getUf() {
		return uf;
	}
}
